#include <iostream>
#include <cmath>
#include <stdlib.h>
#include <time.h>
#include "main.h"


#include "WorldStatusUpdate.pb.h"
#include "Commands.pb.h"
#include "ProtobufUtil.hh"

using namespace strategy_protocol;
using namespace protoutil;
using namespace std;

int main()
{
	size_t i = 0;
	TheStrategy strategy;
	while (cin.good()) {
		clock_t start = clock();
		cerr << "--------------------------" << endl;
		cerr << "Tick: " << i << endl;
		cerr << "Read... " << endl;
		readProtoFromStream(strategy.world, cin);
		cerr << "DONE " << endl;
		cerr << "<tick>\n";
		cerr << "<log>\n";

//		 cerr << "Proto content with DebugString" << endl;
//		 cerr << strategy.world.DebugString() << endl;

		strategy.initialize_tick(i);

		strategy.run();

		cerr << "Write... " << endl;
		writeProtoOnStream(strategy.commands, cout);
		cerr << "DONE " << endl;

		clock_t end = clock();
		cerr << "Tick time: " << (((float)end-start)/CLOCKS_PER_SEC) <<" s" << endl;
		cerr << "</log>\n";
		cerr << "</tick>\n";
		cerr << "--------------------------" << endl;
		++i;
	}

	return 0;
}

